<html>
<head><meta charset="utf-8"><title>Tools for proc-gen Rust · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html">Tools for proc-gen Rust</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213371686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213371686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213371686">(Oct 15 2020 at 01:47)</a>:</h4>
<p>Hello, question. What tools exist that allow me to define a procedure for generating Rust code? Obviously a proc macro can do it, I guess, but what I really want is to capture the <strong>expansion</strong> of a macro... should I just literally write a macro and then dump the macro expansion into a file?</p>



<a name="213376491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213376491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213376491">(Oct 15 2020 at 03:21)</a>:</h4>
<p>"Possibly yes, why do you want to do this?"</p>



<a name="213376493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213376493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213376493">(Oct 15 2020 at 03:21)</a>:</h4>
<p>because your goal might change the answer</p>



<a name="213376977"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213376977" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213376977">(Oct 15 2020 at 03:31)</a>:</h4>
<p>My two interests for this are generally "something akin to closely-steered fuzzing" and "generating piles of code for something that has a predictable structure, like arch intrinsic functions, in a way that is usually too naughty to do in a <code>macro_rules!</code>declaration".</p>



<a name="213377859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213377859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213377859">(Oct 15 2020 at 03:49)</a>:</h4>
<p>This sort of thing is probably very specialized to the task you want to accomplish. when i needed to generate code beyond what macro_rules could do, i just wrote a program that outputs rust code. i didn't use any special libs to try and manipulate the code in a fancy way at like an AST level, because my needs were ultimately fine with just some string templates that i could format the values into and then print it all to stdout.</p>



<a name="213377935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213377935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213377935">(Oct 15 2020 at 03:51)</a>:</h4>
<p>That is Perfectly Reasonable.</p>



<a name="213378513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213378513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213378513">(Oct 15 2020 at 04:04)</a>:</h4>
<p>gonna PR "in order to reach 'C parity' we need a Rust preprocessor" to rust-lang/rfcs (no)</p>



<a name="213378533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213378533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213378533">(Oct 15 2020 at 04:05)</a>:</h4>
<p>@rustbot fcp postpone</p>



<a name="213409941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213409941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213409941">(Oct 15 2020 at 11:22)</a>:</h4>
<p><span class="user-mention" data-user-id="281757">@Jubilee</span> One thing I have done occasionally is generate rust code inside of a build script￼. You can use plain strings or bring in the quote crate. ￼</p>



<a name="213409970"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213409970" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213409970">(Oct 15 2020 at 11:23)</a>:</h4>
<p>Example: <a href="https://github.com/shepmaster/jetscii/blob/master/build.rs">https://github.com/shepmaster/jetscii/blob/master/build.rs</a></p>



<a name="213410005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Tools%20for%20proc-gen%20Rust/near/213410005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Tools.20for.20proc-gen.20Rust.html#213410005">(Oct 15 2020 at 11:23)</a>:</h4>
<p>This is also a way of doing limited kinds of const evaluation before it’s fully supported￼</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>